// JavaScript Document
var name_0='one';
var cursel_0=1;
var ScrollTime=3000;//循环周期（毫秒）
var links_len,iIntervalId;
//var bhTime=0.1;
onload=function(){
  links = document.getElementById("tab1").getElementsByTagName('li');
  var frChangeDiv=document.getElementsByClassName("frChange").item(0);
  links_len=links.length;
  for(var i=0; i<links_len; i++){
    links[i].onmouseover=function(){
      clearInterval(iIntervalId);
      this.onmouseout=function(){
        iIntervalId = setInterval(Next,ScrollTime);
      }
    }
  }
	frChangeDiv.onmouseover=function(){
		clearInterval(iIntervalId);
		this.onmouseout=function(){
		iIntervalId = setInterval(Next,ScrollTime);
		}
	}
  document.getElementById("con_"+name_0+"_"+links_len).parentNode.onmouseover=function(){
    clearInterval(iIntervalId);
    this.onmouseout=function(){
      iIntervalId = setInterval(Next,ScrollTime);
    }
  }
  setTab(name_0,cursel_0);
  iIntervalId = setInterval(Next,ScrollTime);
  var leftBut=document.getElementById("switch_left");
	var rightBut=document.getElementById("switch_right");
	var oul=document.getElementById("switch_ul");
	var ali=oul.getElementsByTagName("li");
	var num=1;//一次切换数量，随意改
	var oneSize=ali[0].offsetWidth;
	var butTrue=true;
	function oulSize()
	{
		oul.style.width=oneSize*ali.length+"px";
	}
	oulSize();
	function ulmove()
	{
		if(butTrue)
		{
			butTrue=false;
			for(var i=0;i<num;i++)
			{
				var oli=ali[i].cloneNode(true);
				oul.appendChild(oli);
				oulSize();
			}
			startMove(oul,{left:-(oneSize*num)},function(){for(var i=0;i<num;i++){oul.removeChild(ali[0]);oul.style.left=0;}butTrue=true;});
		}
	}
	notIntervalId = setInterval(ulmove,3000);
	leftBut.onclick=function()
	{
		ulmove();
	}
	rightBut.onclick=function()
	{
		if(butTrue)
		{
			butTrue=false;
			var gs=ali.length-1;
			for(var i=0;i<num;i++)
			{
				var gs=ali.length-1;
				var oli=ali[gs-i].cloneNode(true);
				oul.insertBefore(oli,ali[0]);
				oulSize();
			}
			oul.style.left=-(oneSize*num)+"px";
			startMove(oul,{left:0},function(){for(var i=0;i<num;i++){var gs=ali.length-1;oul.removeChild(ali[gs]);oul.style.left=0;}butTrue=true;});			
		}
	}
	leftBut.onmouseout=function()
	{
		notIntervalId = setInterval(ulmove,3000);
	}
	rightBut.onmouseout=function()
	{
		notIntervalId = setInterval(ulmove,3000);
	}
	leftBut.onmouseover=function()
	{
		clearInterval(notIntervalId);
	}
	rightBut.onmouseover=function()
	{
		clearInterval(notIntervalId);
	}
	document.getElementById("switch_div").onmouseout=function()
	{
		notIntervalId = setInterval(ulmove,3000);
	}
	document.getElementById("switch_div").onmouseover=function()
	{
		clearInterval(notIntervalId);
	}
}
function setTab(name,cursel){
  cursel_0=cursel;
  for(var i=1; i<=links_len; i++){
    var menu = document.getElementById(name+i);
    var menudiv = document.getElementById("con_"+name+"_"+i);
	var menuli = document.getElementById(name+i);
    if(i==cursel){
      menu.className="off";
      menudiv.style.display="block";
	  if(menudiv.style.display=="block")
	  {
		var intTime=0;
		function gradient()
		{
			if(parseInt(intTime)<100)
			{
				intTime=intTime+10;
				var intBackTime=intTime/50;
				document.getElementById("tab_ul").getElementsByTagName("li").item(cursel-1).style.opacity=intBackTime;
				if(intBackTime==1)
				{
					clearInterval(intTimeId);
					document.getElementById("tab_ul").getElementsByTagName("li").item(cursel-1).style.opacity=1;
					if(links.length>1)
					{
						if(cursel-2>=0)
						{
							document.getElementById("tab_ul").getElementsByTagName("li").item(cursel-2).style.opacity=0;
						}
						else
						{
							document.getElementById("tab_ul").getElementsByTagName("li").item(cursel+1).style.opacity=0;
						}
					}
					intTime=0;
				}
			}
			else
			{
				intTime=0;
				clearInterval(intTimeId);
			}
		}
		var intTimeId=setInterval(gradient,100);
	  }
	  else
	  {
		  document.getElementById("tab_ul").getElementsByTagName("li").item(cursel-1).style.opacity=0;
	  }
	  menuli.style.backgroundColor="#2ea1f8";	  
    }
    else{
      menu.className="";
      menudiv.style.display="none";
	  menuli.style.backgroundColor="#f2f2f2";
    }
  }
}
function Next(){
  cursel_0++;
  if (cursel_0>links_len)
  {
	  cursel_0=1
  }
  setTab(name_0,cursel_0);
}
function Previous(){
	cursel_0--;
	if(cursel_0==0)
	{
		cursel_0=links_len;
	}
  setTab(name_0,cursel_0);
}
document.getElementsByClassName("frc_p1").item(0).onclick=function()
{
	Previous();
}
document.getElementsByClassName("frc_p2").item(0).onclick=function()
{
	Next();
}
function banImgWidth()
{
	var banImgNum=document.getElementById("myjQueryContent").getElementsByTagName("img");
	var offWidth=document.body.offsetWidth;
	if(offWidth>1200)
	{
		for(var i=0;i<banImgNum.length;i++)
		{
			banImgNum.item(i).style.marginLeft=-(1920-offWidth)/2+"px";
		}
	}
	else
	{
		for(var i=0;i<banImgNum.length;i++)
		{
			banImgNum.item(i).style.marginLeft=-(1920-1200)/2+"px";
		}
	}
}
banImgWidth();
window.onresize=function()
{
	banImgWidth();
}